package uk.ac.cam.tcs40.sidnet.formal;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;

public class Formal {

	private final String m_ID;
	private final Date m_Date;
	private final FormalMenu m_FormalMenu;
	private final User m_User;
	private final List<Guest> m_Guests = new LinkedList<Guest>();
	
	private final List<Attendee> m_AttendingList = new LinkedList<Attendee>();

	private final List<String> m_SidnetGuestIDList = new LinkedList<String>();
	
	private static final DateFormat s_Format = new SimpleDateFormat("E d MMMM", Locale.getDefault());
	
	public Formal(String id, Date date, boolean attending, FormalMenu menu) {
		m_ID = id;
		m_Date = date;
		m_User = new User(null, Dietary.NONE, null, attending);
		m_FormalMenu = menu;
	}

	public String getID() {
		return this.m_ID;
	}

	public User getUser() {
		return m_User;
	}
	
	public FormalMenu getMenu() {
		return m_FormalMenu;
	}

	public void addGuest(Guest guest) {
		synchronized (m_Guests) {
			m_Guests.add(guest);
		}
	}

	public void removeGuest(int position) {
		synchronized (m_Guests) {
			m_Guests.remove(position);
		}
	}
	
	public void clearGuests() {
		synchronized (m_Guests) {
			m_Guests.clear();
		}
	}
	
	public int guestCount() {
		synchronized (m_Guests) {
			return m_Guests.size();
		}
	}
	
	public List<Guest> getGuests() {
		synchronized (m_Guests) {
			return m_Guests;
		}
	}
	
	public Date getDate() {
		return m_Date;
	}

	public String getDateString() {
		return s_Format.format(m_Date);
	}
	
	public void addToAttendingList(Attendee attendee) {
		m_AttendingList.add(attendee);
	}
	
	public List<Attendee> getAttendingList() {
		return m_AttendingList;
	}
	
	public void clearAttendingList() {
		m_AttendingList.clear();
	}
	
	public List<String> getSidnetGuestIDList() {
		return m_SidnetGuestIDList;
	}
	
	public void clearSidnetGuestIDList() {
		m_SidnetGuestIDList.clear();
	}
	
	public void addSidnetGuestID(String guestID) {
		m_SidnetGuestIDList.add(guestID);
	}
	
	@Override
	public String toString() {
		if (m_ID == null)
			return null;

		return getDateString();
	}
}
